﻿
using NHibernate.Validator.Constraints;
using TestBat.IModels.Domain;
namespace TestBat.Models.Domain
{
    public abstract class Task : DomainEntity, ITask
    {
        /// <summary>
        /// the task-folder
        /// </summary>
        [NotNull]
        public virtual ITaskFolder TaskFolder
        {
            get { return taskfolder; }
            set
            {
                if (Equals(taskfolder, value))
                    return; // no change needed

                if (taskfolder != null)
                    taskfolder.Tasks.Remove(this); // remove from old task-folder

                taskfolder = value;

                if (taskfolder != null)
                    taskfolder.Tasks.Add(this); // add to new parent's children
            }
        }

        /// <summary>
        /// the maximum reachable points for this task
        /// </summary>
        [Range(Min = 0, Max = 255)]
        public virtual uint MaximumPoints { get; set; }

        /// <summary>
        /// the name of this task
        /// </summary>
        [NotNullNotEmpty]
        [Length(255)]
        public virtual string Name { get; set; }

        // the associated task-folder
        private ITaskFolder taskfolder;
    }
}
